import {Component, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {HireDeviceService} from '../../hireDevice.service';

@Component({
  selector: 'app-order-detail',
  templateUrl: './order-detail.component.html',
  styleUrls: ['./order-detail.component.scss']
})
export class OrderDetailComponent implements OnInit {
  detail: any = {};
  expressModal = {
    visible: false,
    expressList: [],
    name: '',
    num: '',
  };
  rentModal = {
    visible: false,
    list: [],
  };

  constructor(
    private activatedRoute: ActivatedRoute,
    public hireDeviceService: HireDeviceService,
  ) {
  }

  ngOnInit(): void {
    this.hireDeviceService.getOrderDetail(this.activatedRoute.snapshot.queryParams.id).then((res: any) => {
      console.log(res);
      this.detail = res.data;
      this.detail.rentOrder.faceAuthInfo = res.data.rentOrder.faceAuthInfo ? JSON.parse(res.data.rentOrder.faceAuthInfo) : {};
      // this.detail.userCertification.userImage = this.detail?.userCertification?.userImage ? this.detail?.userCertification?.userImage.replace('http:', 'https:') : '';
      // this.detail.userCertification.userBackImage = this.detail?.userCertification?.userBackImage ? this.detail?.userCertification?.userBackImage.replace('http:', 'https:') : '';
      // this.detail.rentOrder.userCertInfo = JSON.parse(res.data.rentOrder.userCertInfo);
    });
  }

  showExpressDetail(express: any) {
    this.expressModal = {
      visible: true,
      expressList: JSON.parse(express?.expressTraces),
      name: express.expressName,
      num: express.expressNum,
    };
  }

  hideExpressModal() {
    this.expressModal = {
      visible: false,
      expressList: [],
      name: '',
      num: '',
    };
  }

  showRentModal(list: any) {
    this.rentModal = {
      visible: true,
      list
    };
  }

  hideRentModal() {
    this.rentModal = {
      visible: false,
      list: []
    };
  }
}
